<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="user.avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info">
            <view class="u_title">
              用户名：{{ name }}
            </view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view>
      </view>
    </view>

    <view class="content-section">
      <view class="mine-actions grid col-3 text-center">
        <view class="action-item" @click="handleServiceteam">
          <view class="iconfont icon-friendfill text-pink icon"></view>
          <text class="text">我的服务队</text>
        </view>
        <view class="action-item" @click="gotoheart">
          <view class="iconfont icon-service text-blue icon"></view>
          <text class="text">我的暖心团</text>
        </view>

        <view class="action-item" @click="gotomydues">
          <view class="iconfont icon-aixin text-green icon"></view>
          <text class="text">党费记录</text>
        </view>
      </view>

      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view class="iconfont icon-user menu-icon"></view>
            <view>编辑资料</view>
          </view>
        </view>

        <view class="list-cell list-cell-arrow" @click="handleAbout">
          <view class="menu-item-box">
            <view class="iconfont icon-aixin menu-icon"></view>
            <view>我的活动</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToSetting">
          <view class="menu-item-box">
            <view class="iconfont icon-setting menu-icon"></view>
            <view>安全设置</view>
          </view>
        </view>
      </view>

    </view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
  import { getUserProfile } from "@/api/system/user"
  import {
    Isjoinheart,
    joinheart
  } from "@/api/team/team"
import user from '../../store/modules/user'
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
        version: getApp().globalData.config.appInfo.version,
        heartid:"-1",
        user:{}
      }
    },
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    onLoad() {
      this.getIsjoinHeart();
      this.getUser()
    },
    methods: {
      getUser() {
        getUserProfile().then(response => {
         this.user=response.data
          console.log(this.user)
        })
      },
      gotomydues(){
        uni.navigateTo({
          url: '/pages/mine/mypartydues/mypartydues'
        })
      },
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToEditInfo() {
        this.$tab.navigateTo('/pages/mine/info/edit')
      },
      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/pages/index')
          })
        })
      },
      handleHelp() {
        this.$tab.navigateTo('/pages/mine/help/index')
      },
      handleAbout() {
        // uni.switchTab({
        //   url: 'pages/work/index'
        // }
		uni.navigateTo({
			url:'/pages/work/JoinActive/JoinActive'
		})
               // this.$tab.navigateTo('/pages/work/JoinActive/JoinActive')
      },
      handleServiceteam() {
        uni.navigateTo({
          url: '/pages/mine/organization/organization'
        })
      },
      handleBuilding() {
        // 跳转暖心团详情
      },
      getIsjoinHeart() {
        Isjoinheart().then(response => {
          this.heartid=response.msg
        })
      },
      gotoheart() {
        // 判断是否加入了暖心团
        //未加入
        if (this.heartid==-1) {
          uni.showModal({
          		title: '提示',
            content: '是否加入暖心团',
            success: function(res) {
        		    if (res.confirm) {
                  //加入暖心团并且获取其teamid
                joinheart().then(response=>{
                  this.heartid=response.msg;
                  //弹窗提示加入成功
                  uni.showToast({
                    title: '加入成功',
                    icon: 'none', //如果要纯文本，不要icon，将值设为'none
                    duration: 2000 //持续时间为 2秒
                  })
                  //跳转页面
                  uni.navigateTo({
                    url: '/pages/mine/myheart/myheart?teamid=' + this.heartid
                  })
                });
            } else if (res.cancel) {
                console.log('用户点击取消');
         			  }
            }
          });
          //已经加入
        } else {
          uni.navigateTo({
            url: '/pages/mine/myheart/myheart?teamid=' + this.heartid,
          })
        }
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ff2121;
    background: url('../../static/images/dj.png')  no-repeat center;
    background-size: 480px;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 45px 15px;
      // background: url('../../static/images/dj1.png')  no-repeat center;
      // background-size: 390px;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px; 
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
